package Bi_Tree;

import java.util.Stack;

public class lc226 {
    public static void main(String[] args) {
        TreeNode node=new TreeNode();
    }
    public TreeNode invertTreepreorder(TreeNode root) {
        //前序遍历完成二叉树反转
        Stack<TreeNode> stack=new Stack<>();
        if(root==null){
            return root;
        }
        TreeNode node=root;
        stack.push(node);
        while (!stack.isEmpty()){
            node=stack.pop();

            TreeNode templeft=node.left;
            TreeNode tempright=node.right;
            node.right=templeft;
            node.left=tempright;

            if(node.right!=null) stack.push(node.right);
            if(node.left!=null) stack.push(node.left);
        }
        return root;


    }
}
